package com.zxl.app.controller.order;

import com.zxl.app.context.UserContext;
import com.zxl.app.service.BookOrderService;
import com.zxl.common.Result;
import com.zxl.common.model.bo.order.BookOrderApply;
import com.zxl.common.model.vo.order.BookOrderStatusVo;
import com.zxl.common.model.vo.order.BookOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author zxw
 * @date 2023/4/1
 */
@Api(tags = "申请订货模块")
@RestController
@RequestMapping("/app/book_order")
public class BookOrderController {
    @Resource
    private BookOrderService bookOrderService;

    @PostMapping("/book")
    @ApiOperation("申请订货")
    public Result book(@RequestBody @Valid BookOrderApply bookOrderApply) {
        bookOrderApply.setMemberId(UserContext.getUserId());
        bookOrderService.book(bookOrderApply);
        return Result.success();
    }

    @GetMapping("/getBookStatus")
    @ApiOperation("获取订货状态")
    public Result<BookOrderStatusVo> getBookStatus(){
        BookOrderStatusVo bookStatus = bookOrderService.getBookStatus(UserContext.getUserId());
        return new Result<>(bookStatus);
    }

    @GetMapping("/getBookInfo")
    @ApiOperation("获取订货申请信息")
    public Result<BookOrderVo> getBookInfo(){
        BookOrderVo bookInfo = bookOrderService.getBookInfo(UserContext.getUserId());
        return new Result<>(bookInfo);
    }


}
